import 'package:flutter/material.dart';
 //import 'consumer.dart';
 //import 'selector.dart';
import 'change_notifier_provider.dart';

import 'view_model.dart';

class ChildWidget extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    final ViewModel vm = ChangeNotifierProvider.of<ViewModel>(context,listen: false);
    return Column(
      children: <Widget>[
        Text(vm.count.toString()),
        RaisedButton(
          child: const Text('Decrease'),
          //每点击一次，将count自增，然后重新build,ShareDataWidget的data将被更新
          onPressed: () {
            vm.count = vm.count - 1;
          },
        )
      ],
    );

    // return Consumer<ViewModel>(
    //   builder: (BuildContext context, ViewModel vm) {
    //     return Column(
    //       children: <Widget>[
    //         Text(vm.count.toString()),
    //         RaisedButton(
    //           child: const Text('Decrease'),
    //           //每点击一次，将count自增，然后重新build,ShareDataWidget的data将被更新
    //           onPressed: () {
    //             vm.count = vm.count - 1;
    //           },
    //         )
    //       ],
    //     );
    //   },
    // );

    // return Column(
    //   children: <Widget>[
    //     Selector<ViewModel, int>(
    //       selector: (BuildContext context, ViewModel vm) => vm.count,
    //       builder: (BuildContext context, int count, Widget child) {
    //         print('count is changed $count');
    //         return Text(count.toString());
    //       },
    //     ),
    //     Selector<ViewModel, String>(
    //       selector: (BuildContext context, ViewModel vm) => vm.test,
    //       builder: (BuildContext context, String test, Widget child) {
    //         print('test is changed $test');
    //         return Text(test.toString());
    //       },
    //     )
    //   ],
    // );
  }
}
